#include <iostream>
using namespace std;
class Animal
{
public:
    char name;
    Animal(char name) : name{name} {}
    // virtual “告诉编译器：这个成员函数启用运行期动态分派（多态）
    virtual void runing()
    {
        cout << "Animal is runing" << endl;
    }
};

class People : public Animal
{
public:
    int height;
    People(char name, int height) : Animal(name), height{height} {}
    void runing() override
    {
        cout << "People is runing" << endl;
    }
    // override修饰符：只能出现在虚函数的重新声明上
    // 基类Animal没有Sing函数，报错
    // void Sing() override
    // {
    //     cout << "People is sing song" << endl;
    // }
};

int main()
{
    Animal *q;
    Animal a1('A');
    People p1('B', 18);
    q = &a1;
    q->runing(); // 访问的是Animal is runing
    q = &p1;
    q->runing(); // 访问的是People is runing
    return 0;
}
